package com.xiaoxiao.springbootstudy.controller;

import com.xiaoxiao.springbootstudy.pojo.Replay;
import com.xiaoxiao.springbootstudy.service.ReplayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@CrossOrigin
public class ReplayController {
    @Autowired
    ReplayService replayService;

    @PostMapping("/saveReplay")
    public Map<String, Object> saveReplay(@RequestBody Replay replay) {
        Map<String, Object> result = new HashMap<>();

        result.put("code", 400);
        result.put("msg", "保存失败");

        try {
            replay.setRedate(new Date());
            replayService.save(replay);
            result.put("code", 200);
            result.put("msg", "保存成功！");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    @GetMapping("/listReplay")
    public Map<String, Object> listReplay(@RequestParam Integer id, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        return replayService.queryReplayListService(id, pageNum, pageSize);
    }
}
